package https

// 设置header头信息
//
//	header	未处理的header头
//	headers	键值对形式的追加/覆盖Header头，数量需要为2n个，格式为：key,val形式
func getHeader(header map[string]string, headers ...string) map[string]string {
	if header == nil {
		header = map[string]string{}
	}
	// 添加JSON设置的请求头
	if _, ok := header["accept"]; !ok {
		header["accept"] = "application/json, text/plain, */*"
	}
	if _, ok := header["Content-Type"]; !ok {
		header["Content-Type"] = "application/json"
	}
	if _, ok := header["accept-language"]; !ok {
		header["accept-language"] = "zh-CN,zh;q=0.9,en;q=0.8"
	}
	if _, ok := header["user-agent"]; !ok {
		header["user-agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"
	}
	if len(headers) > 0 && len(headers)%2 == 0 {
		for i := 0; i < len(headers); i += 2 {
			header[headers[i]] = headers[i+1]
		}
	}
	return header
}
